package com.framework.main.sys.attachment.dao; 

import java.util.List;

import com.framework.base.dao.BaseDao;
import com.framework.base.util.StringUtil;
import com.framework.main.sys.attachment.domain.AttachmentVo;

/**
 * Description:用于处理公文附件与数据库的交互
 * SYS_ATTACHMENT(对应的表名):
 * Company: framework
 * @author：HYH
 * @version 1.0
 * @Date 2011-6-17 下午04:03:01
 */
public class AttachmentDao extends BaseDao {
	
	/**
	 * 根据外键查询有的附件列表
	 * @param foreignId 业务表的主键
	 * @param userTypef 附件的用途 同时也用于区分同一业务不同位置的附件
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<AttachmentVo> toAttachmentListByforeignId(String foreignId,String userTypef){
		StringBuffer queryString=new StringBuffer();
		queryString.append(" where foreignIdf='").append(foreignId).append("'");
		if(StringUtil.nullToEmpty(userTypef).length()>0){
			queryString.append(" and usetypef="+userTypef+"");
		}
		queryString.append(" order by datasortNumf desc");
		List<AttachmentVo> attachmentVoList=this.getSqlMapClientTemplate().queryForList(this.getNameSpace()+"toList",queryString.toString());
		for (int i = 0; i <attachmentVoList.size(); i++) {
			AttachmentVo vo=attachmentVoList.get(i);
			vo.setNewFile(false);
			attachmentVoList.set(i, vo);
		}
		return attachmentVoList;
	}
	
	/**
	 * 根据外键查询有的附件列表
	 * @param foreignId 业务表的主键
	 * @param userTypef 附件的用途 同时也用于区分同一业务不同位置的附件
	 * @return
	 */
	public void doDeleteByForeignId(String foreignId,String userType){
		StringBuffer queryString=new StringBuffer();
		queryString.append(" where foreignIdf='").append(foreignId).append("'");
		if(StringUtil.nullToEmpty(userType).length()>0){
			queryString.append(" and usetypef="+userType+"");
		}
		this.getSqlMapClientTemplate().queryForList(this.getNameSpace()+"",queryString.toString());
	}
}
